<?php
class BXDDbException extends Exception
{
	const DB_CONNECTION_ERROR				= 1;
	const CONNECTION_NAME_NOT_FOUND			= 2;
	const CONNECTION_NOT_FOUND				= 3;
	const DEFAULT_CONNECTION_IS_NOT_ACTIVE	= 4;
	const INSUFFICENT_PARAMS				= 5;
	const INVALID_SQL_QUERY					= 6;
	const TOO_MANY_PARAMS					= 7;
	const PARAM_NOT_FOUND_INTO_QUERY		= 8;
	const INSUFFICENT_BIND_PARAMS			= 9;
	const MIXED_TYPE_BIND					= 10;

	public function __construct($params, $code)
	{
		switch($code)
		{
			case self::DB_CONNECTION_ERROR :
				$message = sprintf("Failed to open the DB connection. ERROR: '%s'", $params);
				break;

			case self::CONNECTION_NAME_NOT_FOUND :
				$message = sprintf("The connection '%s' not found in the list connection available", $params);
				break;

			case self::CONNECTION_NOT_FOUND :
				$message = sprintf("No connection specified for the command '%s'", $params);
				break;

			case self::DEFAULT_CONNECTION_IS_NOT_ACTIVE :
				$message = sprintf("The default connection '%s' is not active", $params);
				break;

			case self::INSUFFICENT_PARAMS :
				$message = sprintf("Insufficient parameters for the query '%s'", $params);
				break;

			case self::INVALID_SQL_QUERY :
				$message = sprintf("Invalid sql query: '%s'", $params);
				break;

			case self::TOO_MANY_PARAMS :
				$message = sprintf("Too many parameters specified for the query: '%s'", $params);
				break;

			case self::PARAM_NOT_FOUND_INTO_QUERY :
				$message = sprintf("Param '%s' not found into query: '%s'", $params[0], $params[1]);
				break;

			case self::INSUFFICENT_BIND_PARAMS :
				$message = sprintf("Insufficient bind params for the query '%s'", $params);
				break;

			case self::MIXED_TYPE_BIND :
				$message = sprintf("Mixed named and positional parameters for the query '%s'", $params);
				break;

			default :
				$message = "Undefined database error";
				break;
		}

		parent::__construct($message, $code);
	}
}
?>